package com.robotserver.orders.jobs;

import com.robotserver.orders.service.TbOrderService;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 淘宝收货订单同步JOB
 * @author jianghan
 * @date 2019-11-08 10:06
 */
@Component
public class TbReceivingOrderSyncJob {
    private static Logger logger = LoggerFactory.getLogger(TbReceivingOrderSyncJob.class);

    @Autowired
    private TbOrderService tbOrderService;
    @Autowired
    private RedissonClient redissonClient;

    /**
     * 每分钟执行一次拉取订单（时间范围是20分钟）
     */
//    @Scheduled(cron="0/45 * * * * ?")
    public void execute(){
        /*logger.debug("TbReceivingOrderSyncJob execute.");

        RLock lock = redissonClient.getLock("service_tbreceiving_order_sync_lock");
        boolean getlock = false;
        try {
            if (getlock=lock.tryLock(0,1, TimeUnit.MINUTES)) {
                logger.debug("execute right.");
                Long tmptime = System.currentTimeMillis();
                Long end_time = tmptime / 1000;                     //截至时间为当前时间
                Long begin_time = (tmptime - 1200000) / 1000;       //起始时间为前20分钟
                TbOrderSyncParam tbOrderSyncParam = new TbOrderSyncParam();
                tbOrderSyncParam.setBegin_time(begin_time);
                tbOrderSyncParam.setEnd_time(end_time);
                tbOrderSyncParam.setType(2);
                tbOrderService.syncOrder(tbOrderSyncParam);
            }else {
                logger.debug("not execute right.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (getlock){
                lock.unlock();
                logger.debug("release lock.");
            }
        }*/
    }
}
